package com.example.imagesharing;

import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MoreActivity extends AppCompatActivity {
    //    private ImageView dzImage;
//    private ImageView clImage;
//    private ImageView shareImage;
    private Boolean yn_dzSwitch = false;
    private Boolean yn_clSwitch = false;
    private Boolean yn_shareSwitch = false;
    private Boolean yn_gzSwitch = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
//        dzImage.findViewById(R.id.dianzan_img);
//        clImage.findViewById(R.id.collect_img);
//        shareImage.findViewById(R.id.share_img);
        final ImageView dzSwitch = findViewById(R.id.dianzan_img);
        final ImageView clSwitch = findViewById(R.id.collect_img);
        final ImageView shareSwitch = findViewById(R.id.share_img);
        final ImageView gzSwitch = findViewById(R.id.gz_img);

        final TextView btText = findViewById(R.id.biaoti_text);
        final TextView msText = findViewById(R.id.miaoshu_text);

        dzSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yn_dzSwitch = !yn_dzSwitch;
                if(yn_dzSwitch){
                    dzSwitch.setImageResource(R.drawable.dd);
                }else{
                    dzSwitch.setImageResource(R.drawable.like_unselect);
                }
            }
        });
        clSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yn_clSwitch = !yn_clSwitch;
                if(yn_clSwitch){
                    clSwitch.setImageResource(R.drawable.c);
                }else{
                    clSwitch.setImageResource(R.drawable.h_unselect);
                }
            }
        });
        shareSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yn_clSwitch = !yn_clSwitch;
                if(yn_clSwitch){
                    shareSwitch.setImageResource(R.drawable.share_select);
                    String text_1 = btText.getText().toString();
                    String text_2 = msText.getText().toString();
//分享函数
                    share(text_1,text_1);
                }else{
                    shareSwitch.setImageResource(R.drawable.share_unselect);
                }
            }
        });
        gzSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yn_gzSwitch = !yn_gzSwitch;
                if(yn_gzSwitch){
                    gzSwitch.setImageResource(R.drawable.gz_unselect);
                }else{
                    gzSwitch.setImageResource(R.drawable.gz_select);
                }

            }
        });
    }
    private void share(String text_1, String text_2) {
        Intent share_intent = new Intent();
        share_intent.setAction(Intent.ACTION_SEND);                  //设置分享行为
        share_intent.setType("text/plain");                         //设置分享内容的类型
        share_intent.putExtra(Intent.EXTRA_SUBJECT, text_1);//添加分享内容标题
        share_intent.putExtra(Intent.EXTRA_COMPONENT_NAME, text_2);//添加分享内容标题
        share_intent = Intent.createChooser(share_intent, "分享");//创建分享的Dialog
        startActivity(share_intent);
    }
    private void share_image(Uri uri) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent = Intent.createChooser(intent, "分享");//创建分享的Dialog
        startActivity(intent);
    }
//    private String getImagePath(Uri uri, String selection) {
//        String path = null;
//
//        Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
//
//        if (cursor != null) {
//            if (cursor.moveToFirst()) {
//                path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
//
//            }
//
//            cursor.close();
//        }
//        return path;
//    }
}
